package com.dongdongshop.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dongdongshop.data.Result;
import com.dongdongshop.em.ResultEnum;
import com.dongdongshop.pojo.TbContent;
import com.dongdongshop.pojo.TbContentCategory;
import com.dongdongshop.service.CategoryService;
import com.dongdongshop.service.ContentService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("content")
public class ContentController {

    @Reference
    private ContentService contentService;
    @Reference
    private CategoryService categoryService;

    @RequestMapping("contentJeep")
    public String contentJeep(Model model){
        List<TbContentCategory> list = categoryService.selectAll();
        model.addAttribute("list",list);
        return "admin/content";
    }
    @RequestMapping("contentCategoryJeep")
    public String contentCategoryJeep(){

        return "admin/content_category";
    }
    @RequestMapping("getContent")
    @ResponseBody
    public Result getContent(){
        List<TbContent> contents = contentService.getContent();
        return Result.response(ResultEnum.SUCCESS).setData(contents);
    }
    @RequestMapping("addInfo")
    @ResponseBody
    public Result addInfo(TbContent tbContent){
       int i = contentService.andInfo(tbContent);
        return Result.response(ResultEnum.SUCCESS);
    }
    @RequestMapping("toUpdate")
    @ResponseBody
    public Result toUpdate(Long id){
       TbContent tbContent = contentService.toUpdate(id);
        return Result.response(ResultEnum.SUCCESS).setData(tbContent);
    }
    @RequestMapping("update")
    @ResponseBody
    public Result update(TbContent tbContent){
       int i = contentService.updatInfoConten(tbContent);
        return Result.response(ResultEnum.SUCCESS);
    }
    @RequestMapping("deleteInfo")
    @ResponseBody
    public Result deleteInfo(Long[] ids){
       int i = contentService.deleteInfoContent(ids);
        return Result.response(ResultEnum.SUCCESS);
    }

}
